home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr49 / gedlib.zip / INSTALL.ZIP / GEDHASH.H < prev    next >
C/C++ Source or Header  |  1992-04-07  |  8KB  |  188 lines

  1. /****************************************************************************
  2.  *
  3.  *      Copyright (c) 1991  Corporation of the President of
  4.  *                          the CHURCH of JESUS CHRIST of LATTER-DAY SAINTS.
  5.  *
  6.  *      All rights reserved.  Unauthorized reproduction of this software is
  7.  *      prohibited and is in violaton of United States copyright laws.
  8.  *
  9.  ****************************************************************************/
  10. /****************************************************************************
  11.  *
  12.  * FILE: GEDHASH.H
  13.  *
  14.  * MODIFICATION HISTORY:
  15.  * ----------------------------------------------------------------------
  16.  * |  Date           | Who | Comments
  17.  * ----------------------------------------------------------------------
  18.  * | 09/12/91 09:58am| LAM | Code only used for external & internal hash functions moved here
  19.  * ----------------------------------------------------------------------
  20.  ****************************************************************************/
  21.  
  22.  
  23. #define BLKLEN 617 /* Length of block on disk. A key/value record must fit in this. */
  24. #define BYTES_PER_REC 160L /* estimated bytes per gedcom record See gedhash_fopen() */
  25. #define when  break; case
  26. #define DEF_ERR 50  /*  Default error code to send to ged_error */
  27. #define DUP_KEY_FOUND 2
  28. #define KVSIZE sizeof(KVPAIR)
  29. #ifndef MAX_XREF_ID_LENGTH
  30. #define MAX_XREF_ID_LENGTH 11
  31. #endif
  32. #define MAX_TAG_LENGTH 20 /* Used in expander function */
  33. #ifndef MAX_MEMORY
  34. #define MAX_MEMORY (LEN)6000
  35. #endif
  36. #ifndef GLIMIT
  37. #define GLIMIT (unsigned long)20000 /* for GLIMIT variable in gedproc.c */
  38. #endif
  39. #define SEEK_SIZ 10  /* Size of seek val returned from gedhash_lookup() */
  40. #define MAX_FILE_H (HSIZ)400  /* Maximum size of hash table that goes to file */
  41. #define MIN_FNAME_SIZ 13  /* Minimum lenth of file name.  Used in gedhash_create_table */
  42. #define PATH_SIZ 120    /* Size of a Full path name of a file */
  43. #define EXT_SIZ 5   /* Size of a file name extention */
  44. #define NO_SUCCESS 0
  45. #define SUCCESS 1
  46. #define KEY_NOT_FOUND -1
  47. #define HTAB_NOT_FOUND -2
  48. #define IO_ERROR -1       /* Returned by elseek(), eread(), etc. */
  49. #define IO_SUCCESS 1       /* Returned by elseek(), eread(), etc. */
  50. #define TRUE 1
  51. #define FALSE 0
  52.  
  53.  
  54. /******* ged_error() error codes *************/
  55.  
  56. #define SEEK_ERR         401
  57. #define READ_ERR         402
  58. #define RECORD_ERR       403
  59. #define CREATE_TABLE_ERR 404
  60. #define XREF_LENGTH_ERR  405
  61. #define INS_ERR          406 /* xref hash insertion error in gedhash_create_xref() */ 
  62. #define NO_TRLR_ERR      407 /* No TRLR tag encountered in gedhash_create_xref() */
  63. #define WRITE_ERR        408  /* Error with write() */
  64. #define OPEN_ERR         409   /* Error with open()  */
  65. #define FOPEN_ERR        410  /* Error with fopen() */
  66. #define BLKLEN_ERR       411 /* Error with open()  */
  67. #define CHNG_FLOPPY      412 /* User must insert a floppy with the right .G00 */
  68. #define PTR_ERR          413 /* Could not find a pointer */
  69. #define SETUP_INSERT_ERR 414 /* Could not insert value into disk hash table from diskSetup */
  70. #define REMOVE_ERR       415 /* Error with remove() */
  71. #define CLOSE_ERR        416 /* Error with close() */
  72. #define GEDFN_ERR        417 /* Error in gedhash_fopen() */
  73.  
  74.  
  75.  
  76.  
  77. /* Returns count of the number of key currently held in the hash table */
  78. #define GEDHASH_COUNT(htab) (htab ? htab->key_count : 0L)
  79.  
  80.  
  81. #ifndef NON_ANSI /* ##paramerter## : ## not allowed on both sides of parameter */
  82. /* So don't have to type cast */
  83. #define GEDHASH_LOOKUP(htab, key, keyLen, val, valLen, status, data_type) (##data_type##*)\
  84.         gedhash_lookup(htab, key, (KSIZ)keyLen, val, (LEN *)valLen, status)
  85. #endif
  86.  
  87. /* A kinder, gentler gedhash_insert.  Values are type-casterated for you. */
  88. #define GEDHASH_INSERT(htab, key, keyLen, val, valLen) \
  89.             gedhash_insert(htab, key, (KSIZ)keyLen, val, (LEN)valLen)
  90.  
  91. #define SET_LENGTH(keyOrVal, len) len = ((len) ? len : strlen(keyOrVal) +1)
  92.  
  93.  
  94. /*********** MACRO NAME: GED_EREAD   DESCRIPTION: Performs read() and checks for error */
  95. #define GED_EREAD(handle, buffer, count) if (read(handle, buffer, count) <= 0) \
  96.     ged_error(READ_ERR, NULL)
  97.  
  98.  
  99. /* Used in ged_create_xref_hash_table() */
  100. typedef enum {
  101.               WANT_LEVEL, WANT_1ST_AT_SIGN_OR_TAG, WANT_XREF,
  102.               WANT_TERMINATOR, HAVE_KEY_WANT_TERMINATOR, WANT_TERMINAT_OR_TRLR_TAG
  103.              }  CX_State;
  104.  
  105. typedef enum { GHFALSE, GHTRUE } GHBool;
  106.  
  107. typedef long MEMSIZ;
  108.  
  109.  
  110. typedef unsigned int LEN;  /* Used to type valLen field of KVPAIR & KVDISK structs */
  111. typedef unsigned int KSIZ; /* Used to type keyLen */
  112. typedef unsigned long HSIZ;  /* Used to type the h field of a HASH_TAB struct */
  113. typedef unsigned long ITSIZ;  /* Used to type the it_pos field of a HASH_TAB struct */
  114.  
  115. /***************** KVPAIR struct -- Memory-based hash table record *********/
  116.  
  117.  
  118. typedef struct hash_cell
  119.   {
  120.   char *key;     /*  look-up key */
  121.   KSIZ keyLen;   /*  length of key */
  122.   char *val;     /*  value associated with key */
  123.   LEN valLen;    /*  Length of val */
  124.   struct hash_cell *next; /* Points to next record in hash table collision list */
  125.   } KVPAIR;
  126.  
  127. /* KVDISK struct--Disk-based hash table record. key and val are positioned behind this record */
  128.  
  129. typedef struct two_len
  130.     {
  131.     KSIZ keyLen;
  132.     LEN valLen;
  133.     unsigned long totalLen; /* When record 1st made, this gets (keyLen + valLen) Also points to nxt blk */
  134.     } KVDISK;
  135.  
  136.  
  137. /******** HASH_TAB struct -- Contains info associated with a hash table *****/
  138.  
  139. typedef struct
  140.   {
  141.   HSIZ h;            /* size of hash table */
  142.   POOL *pool;        /* stores hash table.  Destroyed when written to disk */
  143.   KVPAIR **table;    /* table of pointers to hash table */
  144.   ITSIZ it_pos;      /* iterate position.  Points to begin. of collison list (memory) */
  145.   KVPAIR *mem_iterate; /* points to current position in collision list in memory*/
  146.   long disk_iterate; /* points to current seek position in collision list on disk */
  147.   MEMSIZ maxMemory;  /* maximum memory that this table can use */
  148.   MEMSIZ memoryLeft; /* maximum memroy less memory used by table */
  149.   char hfn[PATH_SIZ];/* hash file name */
  150.   int isMemory;      /* contains value 1 if hash table goes to memory.  Used to
  151.                       * determine if a temporary file should be deleted when
  152.                       * gedhash_close_table is called. */
  153.  
  154.   int fh;            /* hash file handle */
  155.   char gedfn[PATH_SIZ];    /* GEDCOM data file name */
  156.   long est_records;  /* Estimated number of records in the above gedcom file */
  157.   FILE *fg;          /* GEDCOM data file pointer */
  158.   int ged_ext;       /* If .gedfn spans multiple disks, this is used to show current disk
  159.                       * being processed, i.e.,  .GED = -1, .G00 = 0, .G01 = 1, etc. */
  160.   long key_count;    /* The number of keys currently in the table */
  161.   } HASH_TAB;
  162.  
  163.  
  164. int     ged_eclose(int handle);
  165. FILE *  ged_efopen(char *path, char *mode);
  166. int     ged_elseek( int handle, long offset, int origin);
  167. int     ged_eopen(char *filename, int oflag, int pmode);
  168. int     ged_eread(int handle, void *buffer, unsigned count );
  169. int     ged_ewrite(int handle, void *buffer, unsigned int count);
  170. int     gedhash_close_table(HASH_TAB *htab);
  171. int     gedhash_copy(HASH_TAB *htab_dest, HASH_TAB *htab_source);
  172. HASH_TAB *gedhash_create_table(HASH_TAB *htab, char *perm_file, HSIZ hash_size, MEMSIZ max_memory);
  173. HASH_TAB gedhash_create_xref(char *ged_filename, char *hash_filename, HSIZ h_size, MEMSIZ mem_siz);
  174. int     gedhash_delete(HASH_TAB *htab, void * key, KSIZ keyLen);
  175. int     gedhash_destroy_table(HASH_TAB *htab);
  176. NODE *  gedhash_find_xref(HASH_TAB *htab, NODE *dataCtxt);
  177. FILE *  gedhash_fopen(HASH_TAB *htab, char *gedcom_path, char *mode);
  178. char *  gedhash_get_drive(void);
  179. char *  gedhash_get_file(void);
  180. NODE *  gedhash_get_rec_xref(HASH_TAB *htab, char *value);
  181. int     gedhash_insert(HASH_TAB *htab, void *key, KSIZ keyLen, void *val, LEN valLen);
  182. int     gedhash_iterate(HASH_TAB *htab, void *key, KSIZ *keyLen, void *val, LEN *valLen);
  183. void    gedhash_iterate_reset(HASH_TAB *htab);
  184. void *  gedhash_lookup(HASH_TAB *htab, void *key, KSIZ keyLen, void *val, LEN *valLen, int *status);
  185. int     gedhash_pointer(char *filename);
  186. HSIZ    gedh_prime(HSIZ h);
  187. void    *gedh_word_align(void *address);
  188.